<?php
namespace Admin\Controller;

use Admin\Controller\GlobalController;

class SuggestController extends GlobalController
{
    //列表
    public function getlist()
    {
        $pageSize = 20;
        $where = array();
        $user_id = I('get.user_id', 0, 'intval');
        if (!empty($user_id)) {
            $where['user_id'] = $user_id;
        }
        $this->assign('user_id', $user_id == 0 ? '' : $user_id);
        $recordModel = M('suggest');
        $count = $recordModel->where($where)->count();
        $pageObj = new \Admin\Util\Page($count, $pageSize);
        $list = $recordModel->where($where)->order('id desc')->limit($pageObj->firstRow . ',' . $pageObj->listRows)->select();
        $userModel = M('user');
        foreach ($list as $key => $row) {
            $userInfo = $userModel->where(array('user_id' => $row['user_id']))
                                ->find();
            $list[$key]['nickname'] = $userInfo['nickname'];
        }
        $this->assign('list', $list);
        $this->assign('page', $pageObj->show());
        $this->display();
    }

    public function del()
    {
        $id = I('post.id', 0, 'intval');
        $recordModel = M('suggest');
        $recordModel->where(array('id' => $id))->delete();
        $this->ajaxReturn('', 'success', 'TIP_SUCCESS');
    }
}